import 'package:lepig/pages/webView/Web.dart';
import 'package:lepig/widget/AnimBgPage.dart';
import 'package:flui/flui.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';

class MyCenter extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    // TODO: implement createState
    return _MyCenter();
  }
}

class _MyCenter extends State<MyCenter> {
  BuildContext context;


  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    this.context=context;
    // TODO: implement build
    return AnimBgPage(new Column(
      children: <Widget>[
        new Container(
          height: MediaQuery.of(context).padding.top,
        ),
        new Column(
          children: <Widget>[
            //头部
            _header(),
            _balanc(),
            new SizedBox(
              height: 10.0,
            ),
            _boxRow(),
            new SizedBox(
              height: 10.0,
            ),
            _toolBox(),
          ],
        )
      ],
    ));

  }
}

class _header extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Container(
        height: 100.0,
        decoration: BoxDecoration(),
        child: new Padding(
          padding: EdgeInsets.only(left: 10.0, right: 10.0),
          child: new Column(
            children: <Widget>[
              Flex(
                direction: Axis.horizontal,
                children: <Widget>[
                  Expanded(
                    flex: 2,
                    child: new Container(
                      alignment: Alignment.center,
                      height: 100.0,
                      child: new Row(
                        children: <Widget>[
                          new Container(
                            width: 80.0,
                            height: 80.0,
                            margin: EdgeInsets.only(right: 10.0),
                            alignment: Alignment.centerLeft,
                            child: new Container(
                              decoration: BoxDecoration(
                                border: Border.all(
                                    color: Color.fromRGBO(248, 248, 248, 1),
                                    width: 3),
                                borderRadius: BorderRadius.circular(80.0),
                                image: DecorationImage(
                                  image: new NetworkImage(
                                      "http://thirdwx.qlogo.cn/mmopen/vi_32/Zfg5ia3wNE5Cx80XVMQ55lcblElktP7q4ibIlmbyupOhZuTe9hosfojbhMSKPSmoKy5M18LIVfWmY8mbicRB955ibw/132"),
                                  fit: BoxFit.cover,
                                ),
                              ),
                            ),
                          ),
                          new Container(
                            height: 70.0,
                            child: new Column(
                              crossAxisAlignment: CrossAxisAlignment.start,
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: <Widget>[
                                new Text(
                                  "woddp",
                                  style: TextStyle(fontSize: 25.0),
                                ),
                                new Row(
                                  children: <Widget>[
                                    new Text(
                                      "邀请码 ",
                                      style: TextStyle(fontSize: 16.0),
                                    ),
                                    new Container(
                                      decoration: BoxDecoration(
                                        color: Color.fromRGBO(240, 240, 240, 1),
                                        borderRadius:
                                            BorderRadius.circular(10.0),
                                      ),
                                      padding: EdgeInsets.only(
                                          left: 10.0,
                                          right: 10.0,
                                          top: 2.4,
                                          bottom: 2.5),
                                      child: new Text(
                                        "15622",
                                        style: TextStyle(fontSize: 16.0),
                                      ),
                                    ),
                                    new SizedBox(
                                      width: 10,
                                    ),
                                  ],
                                )
                              ],
                            ),
                          )
                        ],
                      ),
                    ),
                  ),
                  Expanded(
                    flex: 1,
                    child: new Row(
                      mainAxisAlignment: MainAxisAlignment.end,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        new Container(
                          child: new Icon(Icons.sms),
                          padding: EdgeInsets.only(top: 20.0),
                          alignment: Alignment.topRight,
                          height: 80.0,
                        ),
                        new SizedBox(
                          width: 10.0,
                        ),
                        new IconButton(icon: new Container(
                          child: new Icon(Icons.settings),
                          padding: EdgeInsets.only(top: 20.0),
                          alignment: Alignment.topRight,
                          height: 80.0,
                        ), onPressed: (){
                          Navigator.of(context).pushNamed("/setting");

                        })
                      ],
                    ),
                  )
                ],
              )
            ],
          ),
        ));
  }
}

//余额板块
class _balanc extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return new Padding(
      padding: EdgeInsets.all(10.0),
      child: new Column(
        children: <Widget>[
          new Padding(
            padding: EdgeInsets.only(left: 30.0, right: 30.0),
            child: new Container(
              height: 40.0,
              decoration: BoxDecoration(
                borderRadius: BorderRadius.only(
                    topRight: Radius.circular(20.0),
                    topLeft: Radius.circular(20.0)),
                color: Colors.black,
              ),
              width: double.infinity,
              child: new Center(
                child: new Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: <Widget>[
                    new Icon(
                      Icons.backup,
                      color: Colors.white,
                    ),
                    new Text(
                      "邀请好友获取更多优惠",
                      style: TextStyle(color: Colors.white),
                    ),
                    new OutlineButton(
                        color: Colors.white,
                        onPressed: () {
                          Navigator.of(context).pushNamed("/share");
                        },
                        child: new Text(
                          "立即邀请",
                          style: TextStyle(color: Colors.white),
                        ))
                  ],
                ),
              ),
            ),
          ),
          new Container(
              height: 140.0,
              width: double.infinity,
              decoration: BoxDecoration(
                  color: Color.fromRGBO(228, 218, 131, 1),
                  borderRadius: BorderRadius.circular(20.0)),
              child: new Padding(
                padding:
                    EdgeInsets.only(left: 20.0, right: 20, top: 10, bottom: 10),
                child: new Column(
                  children: <Widget>[
                    new Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        new Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          mainAxisAlignment: MainAxisAlignment.start,
                          children: <Widget>[
                            new Row(
                              children: <Widget>[
                                new Text(
                                  "账户可用余额",
                                  style: TextStyle(
                                      fontSize: 15.0,
                                      fontWeight: FontWeight.w600),
                                ),
                                new SizedBox(
                                  width: 10.0,
                                ),
                                new Text(
                                  "￥",
                                  style: TextStyle(
                                      fontSize: 12.0,
                                      fontWeight: FontWeight.w600),
                                ),
                                new Text(
                                  "0.00",
                                  style: TextStyle(
                                      fontSize: 20.0,
                                      fontWeight: FontWeight.w600),
                                ),
                              ],
                            ),
                            new Text(
                              "确认收货后下月佣金自动结算",
                              style: TextStyle(fontSize: 12.0),
                            )
                          ],
                        ),
                        OutlineButton(
                          child: Text("提现"),
                          onPressed: () {
                            Navigator.of(context).pushNamed("/withdraw");
                          },
                        )
                      ],
                    ),
                    new SizedBox(
                      height: 10.0,
                    ),
                    new Container(
                      decoration: BoxDecoration(
                        border: Border(bottom: BorderSide(color: Color.fromRGBO(101, 93, 29, 0.1),width:2)),
                      ),
                    ),
                    new SizedBox(
                      height: 10.0,
                    ),
                    new InkWell(
                      child: new Flex(
                        direction: Axis.horizontal,
                        children: <Widget>[
                          Expanded(
                              flex: 1,
                              child:  _balancMoneyLabel("0.0","今日收益")
                          ),
                          Expanded(
                              flex: 1,
                              child:  _balancMoneyLabel("0.0","本月日收益")
                          ),
                          Expanded(
                            flex: 1,
                            child:  _balancMoneyLabel("0.0","上月收益"),
                          )
                        ],
                      ),
                      onTap: (){
                        Navigator.of(context).pushNamed("/income");
                      },
                    )
                  ],
                ),
              ))
        ],
      ),
    );
  }

 Widget _balancMoneyLabel(String money,String label){
   return  new Column(
     children: <Widget>[
       new Text(money,style: TextStyle(
           fontSize: 18.0,
           fontWeight: FontWeight.w600),),
       new SizedBox(
         height: 5.0,
       ),
       new Text(label,style: TextStyle(
           fontSize: 12.0,
           fontWeight: FontWeight.w600),),
     ],
   );
 }

}


//我的订单  找回订单 收藏 足迹 
class _boxRow extends StatelessWidget{
  BuildContext context;

  @override
  Widget build(BuildContext context) {
    this.context=context;
    // TODO: implement buil
     return new Container(
       padding: EdgeInsets.all(10.0),
       child: new Container(
         decoration: BoxDecoration(
           color: Color.fromRGBO(228, 218, 131, 1),
           borderRadius: BorderRadius.all(Radius.circular(10.0)),
         ),
         child: new Flex(direction: Axis.horizontal,
           children: <Widget>[
             Expanded(
               flex: 1,
               child: _item(0xe6af,"我的订单","/myOrder"),
             ),
             Expanded(
               flex: 1,
               child: _item(0xe7f4,"我的团队","/myTeam"),
             ),
             Expanded(
               flex: 1,
               child: _item(0xe7fc,"我的收藏","/myCollection"),
             ),
//             Expanded(
//               flex: 1,
//               child: _item(0xe69d,"我的足迹","/myOrder"),
//             )
           ],
         ),
       ),
     );
  }

  Widget  _item(int icon,String label,String router){
      return new Container(
        decoration: BoxDecoration(
          border: Border(right: BorderSide(color: Color.fromRGBO(101, 93, 29,0.2),width:0.5)),
        ),
        child: new FlatButton(onPressed: (){
          Navigator.of(this.context).pushNamed(router);
        }, child:
        new Column(
          children: <Widget>[
            new SizedBox(
              height: 15,
            ),
            new Icon(new IconData(
              icon,
              fontFamily: "aly",
            ),),
            new SizedBox(
              height: 10,
            ),
            new Text(label),
            new SizedBox(
              height: 15,
            ),
          ],
        )
        ),
      );
  }

}

//使用工具
class _toolBox extends StatelessWidget{
  @override
  Widget build(BuildContext context) {
    // TODO: implement buil
    return new Container(
      width: double.infinity,
      padding: EdgeInsets.all(10.0),
      child: new Container(
        padding: EdgeInsets.all(10.0),
        decoration: BoxDecoration(
          color: Color.fromRGBO(228, 218, 131, 1),
          borderRadius: BorderRadius.all(Radius.circular(10.0)),
        ),
        child: new Column(
          mainAxisAlignment: MainAxisAlignment.start,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            new Text("实用工具",style: TextStyle(
              fontSize: 16.0,
              color: Colors.black45,
              fontWeight: FontWeight.w600
            ),),
            Wrap(
              spacing: 0, // 主轴(水平)方向间距
              runSpacing: 4.0, // 纵轴（垂直）方向间距
              alignment: WrapAlignment.start, //沿主轴方向居中
              children: <Widget>[
                _item(0xe6fe,"找回订单",(){
                  Navigator.of(context).push(new MaterialPageRoute(builder: (_) {
                    return new Web(
                      title: "找回订单",
                      url: "http://192.168.101.2:8200/index.html",
                    );
                  }));
                }),
                _item(0xe737,"联系客服",(){

                }),
                _item(0xe699,"提交反馈",(){

                }),
                _item(0xe691,"使用问题",(){

                }),
              ],
            )
          ],
        ),
      ),
    );
  }

  Widget  _item(int icon,String label,Function onTab){
    return new Container(
      decoration: BoxDecoration(
      ),
      child: new FlatButton(onPressed: onTab, child:
      new Column(
        children: <Widget>[
          new SizedBox(
            height: 15,
          ),
          new Icon(new IconData(
            icon,
            fontFamily: "aly",
          ),),
          new SizedBox(
            height: 10,
          ),
          new Text(label),
          new SizedBox(
            height: 15,
          ),
        ],
      )
      ),
    );
  }

}